/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.product.rest;
import java.util.Arrays;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.modules.product.domain.YxCommissionDetail;
import co.yixiang.modules.product.service.YxCommissionDetailService;
import co.yixiang.modules.product.service.dto.YxCommissionDetailDto;
import co.yixiang.modules.product.service.dto.YxCommissionDetailQueryCriteria;
import lombok.AllArgsConstructor;
import co.yixiang.logging.aop.log.Log;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import co.yixiang.domain.PageResult;
/**
* @author lsh
* @date 2021-07-20
*/
@AllArgsConstructor
@Api(tags = "YxCommissionDetail管理")
@RestController
@RequestMapping("/api")
public class YxCommissionDetailController {

    private final YxCommissionDetailService yxCommissionDetailService;
    private final IGenerator generator;


    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/yxCommissionDetail/download")
    @PreAuthorize("hasAnyRole('admin','YXCOMMISSIONDETAIL_ALL','YXCOMMISSIONDETAIL_SELECT')")
    public void download(HttpServletResponse response, YxCommissionDetailQueryCriteria criteria) throws IOException {
        yxCommissionDetailService.download(generator.convert(yxCommissionDetailService.queryAll(criteria), YxCommissionDetailDto.class), response);
    }

    @GetMapping(value = "/yxCommissionDetail")
    @Log("查询YxCommissionDetail")
    @ApiOperation("查询YxCommissionDetail")
    @PreAuthorize("@el.check('admin','yxCommissionDetail:list')")
    public ResponseEntity<PageResult<YxCommissionDetailDto>> getYxCommissionDetails(YxCommissionDetailQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxCommissionDetailService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping(value = "/yxCommissionDetail")
    @Log("新增YxCommissionDetail")
    @ApiOperation("新增YxCommissionDetail")
    @PreAuthorize("hasAnyRole('admin','YXCOMMISSIONDETAIL_ALL','YXCOMMISSIONDETAIL_CREATE')")
    public ResponseEntity<Object> create(@Validated @RequestBody YxCommissionDetail resources){
        return new ResponseEntity<>(yxCommissionDetailService.save(resources),HttpStatus.CREATED);
    }

    @PutMapping(value = "/yxCommissionDetail")
    @Log("修改YxCommissionDetail")
    @ApiOperation("修改YxCommissionDetail")
    @PreAuthorize("hasAnyRole('admin','YXCOMMISSIONDETAIL_ALL','YXCOMMISSIONDETAIL_EDIT')")
    public ResponseEntity<Object> update(@Validated @RequestBody YxCommissionDetail resources){
        yxCommissionDetailService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除YxCommissionDetail")
    @ApiOperation("删除YxCommissionDetail")
    @PreAuthorize("hasAnyRole('admin','YXCOMMISSIONDETAIL_ALL','YXCOMMISSIONDETAIL_DELETE')")
    @DeleteMapping(value = "/yxCommissionDetail/{id}")
    public ResponseEntity<Object> deleteAll(@PathVariable Long id) {
            yxCommissionDetailService.removeById(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
